<template>
  <div class="app-container">
    <label class="title"
           style="font-size: 20px;color: rgba(0,0,0,.85);font-weight: 600;line-height: 32px">考生考试成绩</label>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学校" prop="zxmc">
        <el-select v-model="queryParams.zxmc" clearable  filterable size="small">
          <el-option
            v-for="dict in zxmcList"
            :key="dict.zxmc"
            :label="dict.zxmc"
            :value="dict.zxmc"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="bjdm">
        <el-select v-model="queryParams.bjdm" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in bjdmList"
            :key="dict.bjdm"
            :label="dict.bjdm"
            :value="dict.bjdm"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="考生" prop="main">
        <el-input
          v-model="queryParams.main"
          placeholder="请输入准考证、考生姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试情况" prop="completedFlag">
        <el-select v-model="queryParams.completedFlag" placeholder="全部" clearable size="small">
          <el-option
            v-for="dict in dict.type.completedFlag"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="resultList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{scope.$index+(queryParams.pageNo-1)*queryParams.pageSize+1}}</span>
        </template>
      </el-table-column>

      <el-table-column label="准考号" align="center" prop="zkh"/>
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="性别" align="center" prop="genderStr"/>
      <el-table-column label="考点" align="center" prop="pointName"/>
      <el-table-column label="考试项目" align="center" prop="examName"/>
      <el-table-column label="项目类型" align="center" prop="typeStr"/>
      <el-table-column label="考试状态" align="center" prop="testStatus"/>
      <el-table-column label="系统成绩" align="center" prop="result">
        <template slot-scope="scope">
          <span v-if="scope.row.resultType=='1'">{{scope.row.result}}</span>
        </template>
      </el-table-column>
      <el-table-column label="人工成绩" align="center" prop="result">
        <template slot-scope="scope">
          <span v-if="scope.row.resultType=='0'">{{scope.row.result}}</span>
        </template>
      </el-table-column>
      <el-table-column label="计分" align="center" prop="fraction"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['business:result:edit']"
          >考试记录
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:result:remove']"
          >异议处理
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 考试记录 -->
    <el-dialog :title="detailTitle" :visible.sync="detailOpen" width="1060px" append-to-body>
      <el-form ref="form" :model="form2" label-width="80px">
        <el-form-item label="准考号" prop="zkh">
          <el-input v-model="form2.zkh" class="rule-input-edit" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form2.name" class="rule-input-edit" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="性别" prop="genderStr">
          <el-input v-model="form2.genderStr" class="rule-input-edit" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="考点" prop="pointName">
          <el-input v-model="form2.pointName" class="rule-input-edit" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="考试项目" prop="examName">
          <el-input v-model="form2.examName" class="rule-input-edit" readonly="readonly"/>
        </el-form-item>
      </el-form>

      <el-table :data="submitList">
        <el-table-column label="序号" type="index" align="center">
          <template slot-scope="scope">
            <span>{{scope.$index+(queryParams.pageNo-1)*queryParams.pageSize+1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="考试批次" align="center" prop="zkh"/>
        <el-table-column label="考试次数" align="center" prop="name"/>
        <el-table-column label="系统成绩" align="center" prop="genderStr"/>
        <el-table-column label="系统成绩" align="center" prop="pointName"/>
        <el-table-column label="人工成绩" align="center" prop="pointName"/>
        <el-table-column label="开始时间" align="center" prop="pointName"/>
        <el-table-column label="结束时间" align="center" prop="pointName"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel2">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 异议处理 -->
    <el-dialog :title="updateTitle" :visible.sync="updateOpen" width="660px" append-to-body>
      <el-form :inline="true" ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="准考号" prop="zkh">
          <el-input v-model="form.zkh" :disabled="true"/>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" :disabled="true"/>
        </el-form-item>
        <el-form-item label="性别" prop="genderStr">
          <el-input v-model="form.genderStr" :disabled="true"/>
        </el-form-item>
        <el-form-item label="考点" prop="pointName">
          <el-input v-model="form.pointName" :disabled="true"/>
        </el-form-item>
        <el-form-item label="考试项目" prop="project">
          <el-input v-model="form.project" :disabled="true"/>
        </el-form-item>
        <el-form-item label="项目类型" prop="xmlx">
          <el-input v-model="form.xmlx" :disabled="true"/>
        </el-form-item>
        <el-form-item label="考试状态" prop="kszt">
          <el-input v-model="form.kszt" :disabled="true"/>
        </el-form-item>
        <el-form-item label="成绩" prop="cj">
          <el-input v-model="form.cj" :disabled="true"/>
        </el-form-item>
        <el-form-item label="处理方式" prop="type" class="formItem">
          <el-select v-model="form.type" placeholder="全部" clearable size="small" class="formInput"
                     @change="changeOption">
            <el-option
              v-for="dict in dict.type.specialTypes"
              :key="dict.value"
              :label="dict.raw.remark"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item id="result" label="成绩" prop="result" class="formItem" style="display: none">
          <el-input v-model="form.result" placeholder="请输入" class="formInput"/>
        </el-form-item>
        <el-form-item label="原因" prop="reason" class="formItem">
          <el-input v-model="form.reason" placeholder="请输入" class="formInput"/>
        </el-form-item>
        <el-form-item label="密码确认" prop="password" class="formItem">
          <el-input v-model="form.password" placeholder="请输入" class="formInput" show-password/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<style>
  .formItem {
    width: 600px;
    text-align: center;
  }

  .formInput {
    width: 400px;
  }
</style>
<style scoped lang="scss">
  .rule-input ::v-deep {
    .el-input__inner {
      border: 0;
    }
  }

  .rule-input-edit ::v-deep {
    .el-input__inner {
      border: 0;
      border-radius: 0px;
    }
  }

  .el-form-item {
    margin-bottom: 10px;
  }
</style>

<script>
  import {
    examSpecialRecords,
    listResult,
    submitList,
    updateResult
  } from '@/api/business/candidateResult/candidateResult'
  import { examProjectsList, schoolClass } from '@/api/business/candidate/candidate'
  import { listSchool } from '@/api/business/school/school'

  export default {
    name: 'Result',
    dicts: ['completedFlag', 'specialTypes'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 考生考试成绩[针对单个项目的成绩]表格数据
        resultList: [],
        // 弹出层标题
        title: '',
        detailTitle: '',
        updateTitle: '',
        // 是否显示弹出层
        open: false,
        detailOpen: false,
        updateOpen: false,
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          zxmc: null,
          bjdm: null,
          main: null,
          completedFlag: null
        },
        // 表单参数
        form: {},
        form2: {},
        // 表单校验
        rules: {
          type: [
            { required: true, message: '处理方式不能为空', trigger: 'blur' }
          ],
          reason: [
            { required: true, message: '原因不能为空', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ]
        },
        zxmcList: [],
        bjdmList: [],
        projectIdList: [],
        submitList: []
      }
    },
    created() {
      listSchool().then(response => {
        this.zxmcList = response.rows
      })
      schoolClass().then(response => {
        this.bjdmList = response.data
      })
      examProjectsList().then(response => {
        this.projectIdList = response.data
      })
      if (this.zxmcList[0] != null) {
        this.queryParams.zxmc = this.zxmcList[0].zxmc
      }
      this.getList()
    },
    methods: {
      /** 查询考生考试成绩[针对单个项目的成绩]列表 */
      getList() {
        this.loading = true
        listResult(this.queryParams).then(response => {
          this.resultList = response.data.records
          this.total = response.data.totalCount
          this.loading = false
        })
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 取消按钮
      cancel2() {
        this.detailOpen = false
        this.reset()
      },
      // 取消按钮
      cancel3() {
        this.updateOpen = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {}
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      //考试记录
      handleDetail(row) {
        this.reset()
        this.form2 = row
        this.detailOpen = true
        this.detailTitle = '考试记录'
        console.log(row)
        let query = {
          ksId: row.id,
          examId: row.examId,
          pointId: row.pointId
        }
        submitList(query).then(response => {
          this.submitList = response.data
        })
      },
      //异议处理
      handleUpdate(row) {
        this.reset()
        this.form = row
        this.updateOpen = true
        this.updateTitle = '异议处理'
        this.form.type = ''
      },
      //处理方式变更
      changeOption(value) {
        if (value == '4') {
          document.getElementById('result').style.display = 'block'
          this.rules.result = { required: true, message: '成绩不能为空', trigger: 'blur' }
        } else {
          document.getElementById('result').style.display = 'none'
          this.rules.result = {}
        }
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            const data = {
              ksId: this.form.id,
              examId: this.form.examId,
              pointId: this.form.pointId,
              reason: this.form.reason
            }
            if (this.form.type == '4') {
              data.result = this.form.result
              const datas = {
                data: data,
                password: this.form.password
              }
              updateResult(datas).then(response => {
                if (response.status === 'success') {
                  this.$modal.msgSuccess('修改成功')
                  this.updateOpen = false
                  this.getList()
                }else{
                  this.$modal.msgSuccess(response.message)
                }
              })
            } else {
              data.password = this.form.password
              data.type = this.form.type
              examSpecialRecords(data).then(response => {
                if (response.status === 'success') {
                  this.$modal.msgSuccess('修改成功')
                  this.updateOpen = false
                  this.getList()
                }else{
                  this.$modal.msgSuccess(response.message)
                }
              })
            }
          }
        })
      }

    }
  }
</script>
